#/bin/bash
#editor by yhzong
#date 2020-07-27
#操作版本系统号检测
OS=`cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/'`

#创建共享目录
share_dir=/home/share
mkdir -p ${share_dir}

#检测服务器是否可以上网，如果不能上网就退出
check_net=`curl -I -m 10 -o /dev/null -s -w %{http_code} www.baidu.com`
if [ ${check_net} -ne 200 ];then
	echo "请检查网络是否正常，能否访问外网"
	exit 1
fi

#安装替换yum源的wget软件
yum install wget -y > /dev/null 2>&1

#替换镜像源为阿里镜像源
echo "更换为阿里云yum源"
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
if [ $OS == '7' ];then
	wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo > /dev/null 2>&1
	wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo >/dev/null 2>&1
	sed -i '/aliyuncs.com/d' /etc/yum.repos.d/*.repo
elif [ $OS == '6' ];then
	wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
        wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
	sed -i '/aliyuncs.com/d' /etc/yum.repos.d/*.repo
else 
	exit 0
fi

#进行nfs的安装配置
yum -y install nfs-utils rpcbind

#赋予权限给共享目录，一般给777的权限
chmod -R 777 ${share_dir}

echo "nfs服端安装已经完成，请配置/etc/exports 中加入相应的客户端"
#启动nfs服务
if [ $OS == '7' ];then
	systemctl start rpcbind
        systemctl start nfs
elif [ $OS == '6' ];then
        systemctl start rpcbind
	service nfs  start
else
	exit 0
fi
#检测nfs是否安装成功
nfs_status=`ps -ef |grep nfs`
if [ -z "${nfs_status}" ];then
	echo "请检查相应的服务和配置文件，installed failure！！！"
else
	echo "congratulation you are successful installed nfs"
fi
